#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 1e6 + 10, INF = 0x3f3f3f3f;
ull P = 131;

int n;
string s;
ull pre[N], pw[N];

ull substr(int l, int r) { return pre[r] - pre[l - 1] * pw[r - l + 1]; }

bool check(int len)
{
    ull prefix = substr(1, len);
    for (int i = 2;i + len - 1 < n;i++) {
        ull x = substr(i, i + len - 1);
        if (x == prefix) return 1;
    }
    return 0;
}

void solve()
{
    cin >> s;
    n = s.length();s = " " + s;

    pw[0] = 1;
    for (int i = 1;i <= n;i++) {
        pw[i] = pw[i - 1] * P;
        pre[i] = pre[i - 1] * P + s[i] - 'a' + 1;
    }

    vector<int> ne(n + 1);
    for (int i = 2, j = 0;i <= n;i++) {
        while (j && s[i] != s[j + 1]) j = ne[j];
        if (s[i] == s[j + 1]) j++;
        ne[i] = j;
    }

    int p = ne[n];
    while (p) {
        if (check(p)) { cout << s.substr(1, p);return; }
        p = ne[p];
    }
    cout << "Just a legend";
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}